<script type="text/javascript">
	$(document).ready(function(){
		$('#content_more').click(function(){
			$('#content_more_detail').toggle();
		});
		$('#content_sort').click(function(){
			$('#content_sort_detail').toggle();
		});
		$('#action').delegate('#dellAll','click',function(){
			$( "#dialog:ui-dialog" ).dialog( "destroy" );
			$( "#dialog-confirm" ).dialog({
				resizable: false,
				height:180,
				modal: true,
				buttons: {
					"Xóa toàn bộ": function() {
						$( this ).dialog( "close" );
						del_all();
					},
					"Thoát": function() {
						$( this ).dialog( "close" );
					}
				}
			});
		});	
		
		// Ẩn toàn bộ
		$('#action').delegate('#hideAll','click',function(){
			$( "#dialog:ui-dialog" ).dialog( "open" );
			$( "#hide-confirm" ).dialog({
				resizable: false,
				height:180,
				modal: true,
				buttons: {
					"Ẩn toàn bộ": function() {
						$( this ).dialog( "close" );
						hide_all();
					},
					"Thoát": function() {
						$( this ).dialog( "close" );
					}
				}
			});
		});	
		
		// Show toàn bộ
		$('#action').delegate('#showAll','click',function(){
			$( "#dialog:ui-dialog" ).dialog( "open" );
			$( "#show-confirm" ).dialog({
				resizable: false,
				height:180,
				modal: true,
				buttons: {
					"Hiện toàn bộ": function() {
						$( this ).dialog( "close" );
						show_all();
					},
					"Thoát": function() {
						$( this ).dialog( "close" );
					}
				}
			});
		});	
		
		$('#checkAll').click(function(){
			$('.table_tr').find(':checkbox').attr('checked', this.checked);
		});
	});
	
	function change_status(id_post,status)
	{
		var url	= "<?=base_url().'index.php/admin/'.$module.'/update_status/'?>";
		
		$.post(url,{id:id_post,status:status},function(data){
			$('#ajax_status_'+id_post).html(data);
		});
	}
	
	function change_bestsale(id_post,bestsale)
	{
		var url	= "<?=base_url().'index.php/admin/'.$module.'/update_bestsale/'?>";
		
		$.post(url,{id:id_post,bestsale:bestsale},function(data){
			$('#ajax_best_'+id_post).html(data);
		});
	}
	
	function del_all(){
			$('#del_all_item').submit();
	}
	
	function sort_by(value)
	{
		var url = "<?=base_url().'index.php/admin/'.$module.'/sort/'?>"
		$.post(url,{value: value},function(data){
			$('#ajax_list_post').html(data);
		});
	}
	
	function show_all()
	{
		if(document.getElementById('check_item_0')!=null){
			max = <?=count($result)?>;
			for(var i=0;i<max;i++){
				if(document.getElementById('check_item_'+i).checked==true){
					change_status($('#check_item_'+i).val(),0);
				}
				document.getElementById('check_item_'+i).checked=false;
			}
			document.getElementById('check_all').checked=false;
		}else{
			return false;
		}
	}
	
	function hide_all()
	{
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"Delete all items": function() {
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		
		var hide = confirm("Bạn có chắc chắn ẩn toàn bộ?");
		if(hide)
		{
			if(document.getElementById('check_item_0')!=null){
				max = <?=count($result)?>;
				for(var i=0;i<max;i++){
					if(document.getElementById('check_item_'+i).checked==true){
						change_status($('#check_item_'+i).val(),1);
					}
					document.getElementById('check_item_'+i).checked=false;
				}
				document.getElementById('check_all').checked=false;
			}else{
				return false;
			}
		}
	}
</script>
<div class="main_action">
	<div class="content_post_title pt14">
		<div id="content_sort" class="button left" style="position:relative;">
			<div style="float:left;">Sort</div>
			<div style="float:left;"><img src="<?=base_url().'static/images/arrow_down.png'?>" alt="" style="padding-top:15px;padding-left:5px;"/></div>
			<div class="clearall"></div>
		</div>
		<div class="clearall"></div>
		<div id="content_sort_detail" class="content_wrap_sort left content_more" style="display:none;position:absolute;z-index:10;top:139px;">
			<div class="more_line" onclick="return sort_by(9999)">All</div>
			<div class="more_line" onclick="return sort_by(1)">Available</div>
			<div class="more_line" onclick="return sort_by(2)">Unavailable</div>
			<div class="more_line" onclick="return sort_by(3)">Call</div>
			<div class="more_line" onclick="return sort_by(4)">Promotion</div>
			<div class="more_line" onclick="return sort_by(5)">Best sale</div>
			<div class="more_line" onclick="return sort_by(6)">Active</div>
			<div class="no_more_line" onclick="return sort_by(7)">Unactive</div>
			
		</div> 
		<div class="clearAll"></div>
	</div>
	<div class="content_post_action pt14" id="action">
		<div class="button mr16 opacity_half left" onclick="location.href='<?=base_url().'index.php/admin/'.$module.'/update/'?>'" title="Tạo mới bài viết">Add</div>
		<div class="button left">
			<div class="search_icon_hide opacity_half" title="Hiện sản phẩm" id="showAll">&nbsp;</div>
		</div>
		<div class="button left">
			<div class="search_icon_hide opacity_half" title="Ẩn sản phẩm" id="hideAll">&nbsp;</div>
		</div>
		<div class="button left">
			<div class="search_icon_del opacity_half" title="Xóa sản phẩm" id="dellAll">&nbsp;</div>
		</div>
	</div>
	<div class="clearAll"></div>
</div>
<div class="right_content" id="right_content">
	<div id="ajax_list_post">
	<?php $this->load->view("BACKEND/ajax_index");?>
	</div>
</div>
<div class="content_paginator">
	<?=$this->pagination->create_links()?>
	<div class="clearall"></div>
</div>

<!-- Load Dialog -->
<div id="dialog-confirm" title="Bạn có muốn xóa không?" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>			Khi đồng ý, mọi dữ liệu sẽ bị xóa. Bạn đồng ý chứ?
	</p>
</div>
<!-- hide all -->
<div id="hide-confirm" title="Bạn có muốn ẩn toàn bộ?" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>			Bạn muốn ẩn toàn bộ. Bạn đồng ý chứ?
	</p>
</div>
<!-- show all -->
<div id="show-confirm" title="Bạn có muốn hiện toàn bộ?" style="display:none;">
	<p>
		<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>			Bạn muốn hiện toàn bộ. Bạn đồng ý chứ?
	</p>
</div>